# +----------------------------------------------------------------------
# | ChatWork智能聊天办公系统
# +----------------------------------------------------------------------
# | 软件声明: 本系统并非自由软件,未经授权任何形式的商业使用均属非法。
# | 版权保护: 任何企业和个人不允许对程序代码以任何形式任何目的复制/分发。
# | 授权要求: 如有商业使用需求,请务必先与版权所有者取得联系并获得正式授权。
# +----------------------------------------------------------------------
# | Author: ChatWork Team <2474369941@qq.com>
# +----------------------------------------------------------------------
from decimal import Decimal
from typing import Union, List, Dict, Any
from fastapi import Query
from pydantic import BaseModel, Field


class RobotSearchIn(BaseModel):
    """ 智能体搜索参数 """
    page_no: int = Query(default=1, gt=0, description="当前页码")
    page_size: int = Query(default=15, gt=0, le=200, description="每页条数")
    name: Union[str, None] = Query(default=None, description="智能体名称")
    user: Union[str, None] = Query(default=None, description="用户信息")
    is_disable: Union[str, int, None] = Query(default=None, description="是否禁用: [0=否, 1=是]")


class RobotDetailIn(BaseModel):
    """ 智能体详情参数 """
    id: int = Query(..., gt=0, description="智能体ID")


class RobotPostIdIn(BaseModel):
    """ 智能体ID参数 """
    id: int = Field(gt=0, description="智能体ID", examples=[1])
    reason: str = Field(default="", description="原因描述")

    class Config:
        json_schema_extra = {
            "example": {
                "id": 1,
                "reason": "原因说明"
            }
        }


"""--------------- Separator ---------------"""


class RobotListVo(BaseModel):
    """ 智能体列表Vo """
    id: int = Field(description="智能体ID")
    code: str = Field(description="智能体编号")
    logo: str = Field(description="智能体图标")
    name: str = Field(description="智能体名称")
    model: str = Field(description="智能体模型")
    mcp_num: int = Field(description="MCP数量")
    know_num: int = Field(description="知识库数量")
    search_mode: str = Field(description="检索模式")
    search_tokens: int = Field(description="检索引用上限")
    search_similar: Decimal = Field(description="检索相似: [0.0~1.0]")
    ranking_status: int = Field(description="检索的重排: [0=否, 1=是]")
    optimize_ask: int = Field(description="问题的优化: [0=否, 1=是]")
    is_disable: int = Field(description="是否禁用: [0=否, 1=是]")
    create_time: str = Field(description="创建时间")
    update_time: str = Field(description="更新时间")
    user: dict = Field(description="拥有者")

    class Config:
        json_schema_extra = {
            "example": {
                "id": 1,
                "code": "a51q4txg58fbb6vk",
                "logo": "https://waitadmin.cn/static/default/images/robot.png",
                "name": "必问智能体",
                "model": "GPT4.0:gpt-4o",
                "mcp_num": 3,
                "know_num": 2,
                "search_mode": "similar",
                "search_tokens": 5000,
                "search_similar": 0.4,
                "ranking_status": 0,
                "optimize_ask": 0,
                "is_disable": 0,
                "create_time": "2024-11-02 20:34:18",
                "update_time": "2024-11-03 21:43:14",
                "user": {
                    "sn": "80965941",
                    "nickname": "Wait",
                    "mobile": "13800138000",
                    "avatar": "https://waitadmin.cn/storage/image/20241102/46fa2b2eb9b531049f9.png"
                }
            }
        }


class RobotDetailVo(BaseModel):
    """ 智能体详情VO """
    code: str = Field(description="智能体编号")
    type: str = Field(description="智能体类型")
    logo: str = Field(description="智能体图标")
    name: str = Field(description="智能体名称")
    intro: str = Field(description="智能体简介")
    search_mode: str = Field(description="检索的模式: [语义, 全文, 混合]")
    search_tokens: int = Field(description="检索引用上限: [0 ~ 30000]")
    search_similar: Decimal = Field(description="检索相似度: [0 ~ 1]")
    ranking_status: int = Field(description="检索的重排: [0=否, 1=是]")
    optimize_ask: int = Field(description="问题的优化: [0=否, 1=是]")
    prompt_roles: str = Field(description="角色提示词")
    prompt_limit: str = Field(description="限定提示词")
    welcome_text: str = Field(description="欢迎光临词")
    question_guide: int = Field(description="猜您想问的")
    empty_search_text: str = Field(description="空搜索文本")
    empty_search_type: str = Field(description="空搜索类型: [ai, default]")
    max_upload_num: int = Field(description="最大上传数")
    is_upload_files: int = Field(description="文档上传: [0=否, 1=是]")
    is_upload_image: int = Field(description="图片上传: [0=否, 1=是]")
    is_show_timed: int = Field(description="显示耗时: [0=否, 1=是]")
    is_show_quote: int = Field(description="显示引用: [0=否, 1=是]")
    is_show_context: int = Field(description="显上下文: [0=否, 1=是]")
    is_original_reply: int = Field(description="原文答复: [0=否, 1=是]")
    llm_name: str = Field(description="模型名称")
    llm_models: str = Field(description="对话的模型")
    llm_config: List[dict] = Field(description="对话的模型")
    broadcast: Dict[str, Union[str, int, float, list]] = Field(description="语音播报参")
    knows: List[Any] = Field(description="关联知识库")
    mcps: List[Any] = Field(description="关联MCP")

    class Config:
        json_schema_extra = {
            "example": {
                "code": "HCxiS50f0d4nd",
                "type": "simple",
                "logo": "https://www.waitadmin.cn/images/logo.png",
                "name": "智能体名称",
                "intro": "智能体简介",
                "search_mode": "similar",
                "search_tokens": 6000,
                "search_similar": 0.4,
                "ranking_status": 0,
                "optimize_ask": 0,
                "prompt_roles": "",
                "prompt_limit": "",
                "welcome_text": "",
                "question_guide": 0,
                "empty_search_text": "",
                "empty_search_type": "ai",
                "max_upload_num": 0,
                "is_upload_files": 0,
                "is_upload_image": 0,
                "is_show_timed": 0,
                "is_show_quote": 0,
                "is_show_context": 0,
                "is_original_reply": 0,
                "llm_name": "OpenAI",
                "llm_models": "openai:gpt-3.5-turbo-0125",
                "llm_config": [
                    {
                        "key": "context_num",
                        "name": "context",
                        "type": "slider",
                        "default": 3,
                        "range": [0, 10],
                        "step": 1,
                        "tips": "Control the number of contexts"
                    }
                ],
                "knows": [
                    {
                        "code": "wZS3mj23aj6kP",
                        "logo": "https://www.waitadmin.cn/images/legal.png",
                        "name": "知识库名称",
                        "vector_name": "OpenAI",
                        "vector_model": "openai:text-embedding-ada-002",
                        "is_disable": 0
                    }
                ],
                "mcps": [
                    {
                        "code": "wZS3mj23aj62P",
                        "logo": "https://www.x.cn/images/legal.png",
                        "name": "mcp",
                        "is_disable": 0
                    }
                ],
                "broadcast": {
                    "model": "xunfei:x4_lingxiaoxuan_oral",
                    "speed": 0.25,
                    "speed_range": [0.1, 10, 0.1]
                }
            }
        }


class RobotMcpVo(BaseModel):
    """ 智能体MCP工具VO """
    code: str = Field(description="编号")
    logo: str = Field(description="图标")
    name: str = Field(description="名称")
    is_disable: int = Field(description="是否禁用: [0=否, 1=是]")

    class Config:
        json_schema_extra = {
            "example": {
                "code": "wZS3mj23aj62P",
                "logo": "https://www.xx.cn/logo.png",
                "name": "知识库名称",
                "is_disable": 0
            }
        }